package components.bullets.controller
{
	import capricornus.utils.PointUtils;
	
	import components.bullets.Bullet;
	
	public class BulletParabolaMoveController extends BulletMoveController
	{
		/**
		 * 子弹垂直方向距离 
		 */		
		private var _height:Number = 0;
		/**
		 * 子弹垂直方向速度 
		 */		
		private var _us:Number;
		/**
		 * 子弹垂直方向加速度，这个是变化的，因为如果击中目标是怪物的话，怪物是要经常走动的；也可以不变 
		 */		
		private var _g:Number = 1;
		
		public function BulletParabolaMoveController(bullet:Bullet)
		{
			super(bullet);
			init();
		}
		
		private function init():void
		{
			_showLen = 10;
			_us = -8;
			_height = -Math.abs(_bullet.container.y);
		}
		
		override public function setInfo(endHeight:int, diffHeight:int):void
		{
			diffHeight += endHeight;
			endHeight = 0;
			
			super.setInfo( endHeight, diffHeight );
		}
		
		override public function refresh(time:int):void
		{
			super.refresh( time );
			if( _bullet != null )
			{
				_height += _us;
				{
					//如果目标点不变的话，就注释掉此处，当然_g一开始就要算好了
					var t:Number = _len/_speed/20;
					_g = (Math.abs(_bullet.container.y) - _us * t) / (0.5 * t * t);
				}
				_us += _g;
				_bullet.container.y = int(_height);
			}
		}
	}
}